package com.ts.api.module.api.entity.bo;

import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.IteratorUtils;
import com.ts.api.common.constant.product.ProductPlanTypeEnum;
import lombok.Data;

import java.util.List;

/**
 *  匹配计划实体业务
 *
 *  @author Pan
 */
@Data
public class ApiBizMatchBO {

    /** 是否开启唤醒默认false */
    private Boolean enableWake = false;
    /** 匹配的城市计划类型 */
    private List<ProductPlanTypeEnum> listPlanType;

    public ApiBizMatchBO() {
        super();
        this.listPlanType = CollUtils.newArrayList(10);
    }

    /**
     *  将枚举转化listInteger
     *
     *  @return List
     */
    public List<Integer> listPlanToListInt() {
        List<Integer> list = CollUtils.newArrayList();
        this.listPlanType.forEach(planType -> list.add(planType.getType()));
        return list;
    }

    /**
     *  是否只存在特殊计划
     *
     *  @return boolean
     */
    public boolean hasOnlySpecialPlan() {
        ProductPlanTypeEnum special = CollUtils.findOne(this.listPlanType, t -> t.hasType(ProductPlanTypeEnum.SPECIAL.getType()));
        return this.listPlanType.size() == 1 && special != null;
    }

    /**
     *  创建所有计划类型匹配
     *
     *  @param  enableWake  true开启唤醒
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createAllPlan(boolean enableWake) {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList();
        IteratorUtils.array(ProductPlanTypeEnum.values(), productPlanTypeEnum -> listPlanType.add(productPlanTypeEnum));

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setEnableWake(enableWake);
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }

    /**
     *  创建正常计划类型匹配（机构）
     *
     *  @param  enableWake  true开启唤醒
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createOrgPlan(boolean enableWake) {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList(newList -> newList.add(ProductPlanTypeEnum.ORG));

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setEnableWake(enableWake);
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }

    /**
     *  创建正常计划类型匹配（机构、平台）
     *
     *  @param  enableWake  true开启唤醒
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createNormalPlan(boolean enableWake) {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList(newList -> {
            newList.add(ProductPlanTypeEnum.ORG);
            newList.add(ProductPlanTypeEnum.PLATFORM);
        });

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setEnableWake(enableWake);
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }

    /**
     *  创建特殊计划类型匹配（特殊主题）
     *
     *  @param  enableWake  true开启唤醒
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createSpecialPlan(boolean enableWake) {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList(newList -> newList.add(ProductPlanTypeEnum.SPECIAL));

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setEnableWake(enableWake);
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }

    /**
     *  创建进件-正常计划类型匹配（机构、平台）
     *
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createNormalPlanApply() {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList(newList -> {
            newList.add(ProductPlanTypeEnum.ORG);
            newList.add(ProductPlanTypeEnum.PLATFORM);
        });

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setEnableWake(false);
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }

    /**
     *  创建进件-特殊计划类型匹配（特殊主体）
     *
     *  @return ApiBizMatchBO
     */
    public static ApiBizMatchBO createSpecialPlanApply() {
        List<ProductPlanTypeEnum> listPlanType = CollUtils.newArrayList(newList -> newList.add(ProductPlanTypeEnum.SPECIAL));

        ApiBizMatchBO apiBizMatchBO = new ApiBizMatchBO();
        apiBizMatchBO.setListPlanType(listPlanType);
        return apiBizMatchBO;
    }
}
